"use strict";(globalThis.webpackChunk_github_ui_github_ui=globalThis.webpackChunk_github_ui_github_ui||[]).push([["packages_copilot-chat_components_tracing_TraceProvider_tsx"],{8891:(e,t,a)=>{a.d(t,{L:()=>BlackbirdPermissionCaches});var s=a(50467),i=a(21067),r=a(96379),o=a(51987);let BlackbirdPermissionCaches=class BlackbirdPermissionCaches{async setupWarmCachesLoop(){(0,i.M3)()&&(BlackbirdPermissionCaches.warmCachesLoopSetup?await BlackbirdPermissionCaches.warm:(BlackbirdPermissionCaches.warmCachesLoopSetup=!0,await this.warmCaches()))}async warmCaches(){let e=54e4;try{let t=await (0,r.lS)("/search/warm_blackbird_caches",{headers:{Accept:"application/json",...(0,o.kt)()}}),a=await t.json();e=new Date(a.userCacheExpiresAt).getTime()-Date.now()-3e4,(isNaN(e)||e<=5)&&(e=3e4)}catch{}BlackbirdPermissionCaches.warmResolve(),setTimeout(()=>{this.warmCaches()},e)}};(0,s._)(BlackbirdPermissionCaches,"warmCachesLoopSetup",!1),(0,s._)(BlackbirdPermissionCaches,"warmResolve",void 0),(0,s._)(BlackbirdPermissionCaches,"warm",new Promise(e=>{BlackbirdPermissionCaches.warmResolve=e}))},14095:(e,t,a)=>{a.d(t,{Z:()=>d});var s=a(50467),i=a(53419),r=a(97665),o=a(97286),n=a(96379),l=a(96540),u=a(25641),c=a(51213),h=a(35247);function d(e,t,a){let s=(0,r.jE)(),d=(0,l.useCallback)(()=>s.invalidateQueries({queryKey:["copilot-chat","entitlement"]}),[s]),{data:p}=(0,o.I)({queryKey:["copilot-chat","entitlement"],queryFn:async()=>{let e=await (0,n.lS)("/github-copilot/chat/entitlement");if(!e.ok)throw Error(`Failed to retrieve Copilot chat entitlement (${e.status} on ${e.url})`);return await e.json()},enabled:e===c.mF.LicensedLimited||e===c.mF.LicensedFull&&h.W.premiumRequestQuotasEnabled,placeholderData:{licenseType:e,plan:t,quotas:a},staleTime:3e5}),m=p?.licenseType??e,f=p?.plan??t,g=p?.quotas??a,k=(0,l.useCallback)(t=>{(e===c.mF.LicensedLimited||e===c.mF.LicensedFull&&h.W.premiumRequestQuotasEnabled)&&(h.W.reduceChatQuotaChecks&&m===c.mF.LicensedLimited&&g?.remaining.chatPercentage!==void 0&&g.remaining.chatPercentage>u.fG||m===c.mF.LicensedFull&&g?.remaining.premiumInteractionsPercentage!==void 0&&g.remaining.premiumInteractionsPercentage>u.mF||(d(),(0,i.BI)("dotcom_chat.activate",{target:"ENTITLEMENTS_RELOAD",origin:t})))},[e,d,m,g?.remaining.chatPercentage,g?.remaining.premiumInteractionsPercentage]);return[new CopilotChatEntitlement(m,f,p?.quotas,p?.trial),k]}let CopilotChatEntitlement=class CopilotChatEntitlement{isLicensed(){return this.licenseType&&this.licenseType!==c.mF.Unlicensed}canPurchaseAdditionalQuota(){return this.licenseType!==c.mF.LicensedLimited&&h.W.premiumRequestQuotasEnabled&&(this.plan===c.UH.IndividualPro||this.plan===c.UH.IndividualProPlus)}canUpgradePlan(){return this.licenseType===c.mF.LicensedLimited||h.W.premiumRequestQuotasEnabled&&this.plan===c.UH.IndividualPro}chatQuotaRemaining(){return h.W.premiumRequestQuotasEnabled&&this.quotas?.remaining.chatPercentage!==void 0?this.quotas?.remaining.chatPercentage??0:this.quotas?.remaining.chat??0}premiumInteractionsQuotaRemaining(){return this.quotas?.remaining.premiumInteractionsPercentage??0}eligibleForTrial(){return this.trial?.eligible??!1}constructor(e,t,a,i){(0,s._)(this,"licenseType",void 0),(0,s._)(this,"plan",void 0),(0,s._)(this,"quotas",void 0),(0,s._)(this,"trial",void 0),this.licenseType=e,this.plan=t,this.quotas=a,this.trial=i}}},14457:(e,t,a)=>{a.d(t,{d:()=>ApiCache});var s=a(50467);let ApiCache=class ApiCache{async get(...e){let t=e.join(this.separator),a=this.cache.get(t);if(a)return a;{let a=this.fetchFn(...e);return this.cache.set(t,a),(await a).ok||this.cache.delete(t),a}}constructor(e){(0,s._)(this,"separator","-!-"),(0,s._)(this,"cache",new Map),(0,s._)(this,"fetchFn",void 0),this.fetchFn=e}}},20139:(e,t,a)=>{a.d(t,{k:()=>CopilotChatService});var s=a(50467),i=a(8891),r=a(65411),o=a(25407),n=a(96379),l=a(14457),u=a(25641),c=a(35247),h=a(79064),d=a(57872),p=a(44902),m=a(46062);let f=new Set(["snippet","file","symbol","docset","repository"]);let CopilotChatService=class CopilotChatService{async fetchMCPServers(){let e=await this.makeCAPIRequest("/mcps","GET");if(!e.ok)throw Error(`Failed to fetch MCP servers: ${e.status}`);return(await e.json()).servers}async fetchThreads(e={}){let t=new URLSearchParams;"string"==typeof e.name&&t.set("name",e.name);let a=`/threads?${t.toString()}`,s=await this.makeCAPIRequest(a,"GET");if(!s.ok)return s;let i=(await s.json()).threads||[];return{status:s.status,ok:!0,payload:i}}async fetchSharedThreads(){let e=await this.makeCAPIRequest("/threads?shared","GET");if(!e.ok)return e;let t=(await e.json()).threads||[];return{status:e.status,ok:!0,payload:t}}async fetchLatestThread(e){let t=new URLSearchParams;"string"==typeof e&&t.set("thread_id",e);let a=await this.makeCAPIRequest(`/threads/latest?${t.toString()}`,"GET");if(!a.ok)return a;let s=(await a.json()).thread;return{status:a.status,ok:!0,payload:s}}async createThread(e,t){let a={custom_copilot_id:e?.id,custom_copilot_owner:e?.owner,scope_id:t},s=await this.makeCAPIRequest("/threads","POST",a);if(!s.ok)return s;let i=(await s.json()).thread;return{status:s.status,ok:!0,payload:i}}async deleteThread(e){let t=await this.makeCAPIRequest(`/threads/${e}`,"DELETE");return t.ok?{status:t.status,ok:!0,payload:null}:t}async deleteAllThreads(e){let t=await this.makeCAPIRequest("/threads","DELETE",e);return t.ok?{status:t.status,ok:!0,payload:null}:t}async renameThread(e,t){let a=await this.makeCAPIRequest(`/threads/${e}/name`,"PATCH",{generate:!1,name:t});if(!a.ok)return a;let s=(await a.json()).name||"";return{status:a.status,ok:!0,payload:s}}async clearThread(e){let t=await this.makeCAPIRequest(`/threads/${e}/clear`,"PATCH");return t.ok?{status:t.status,ok:!0,payload:null}:t}async shareThread(e,t){let a=await this.makeCAPIRequest(`/threads/${e}/share`,"PATCH",{shared_message_id:t});if(!a.ok)return a;let s=(await a.json()).thread;return{status:a.status,ok:!0,payload:s}}async unshareThread(e){let t=await this.makeCAPIRequest(`/threads/${e}/unshare`,"PATCH");if(!t.ok)return t;let a=(await t.json()).thread;return{status:t.status,ok:!0,payload:a}}async unshareAllThreads(){let e=await this.makeCAPIRequest("/threads/unshare","POST");return e.ok?{status:e.status,ok:!0,payload:null}:e}async continueSharedThread(e){let t=await this.makeCAPIRequest(`/shared/${e}/duplicate`,"POST");return t.ok?{status:200,ok:!0,payload:await t.json()}:t}async generateThreadName(e){let t=await this.makeCAPIRequest(`/threads/${e}/name`,"PATCH",{generate:!0,name:""});if(!t.ok)return t;let a=(await t.json()).name||"";return{status:t.status,ok:!0,payload:a}}async getSystemPrompt(e){let t=await this.makeCAPIRequest(`/system_prompt/${e}`,"GET");if(!t.ok)return t;let a=await t.json();return{status:t.status,ok:!0,payload:a}}async listMessages(e){if(this.listMessagesCache?.thread.id===e)return{status:200,ok:!0,payload:this.listMessagesCache};let t=await this.makeCAPIRequest(`/threads/${e}/messages`,"GET");return this.handleListMessages(t,!0)}async listSharedThreadMessages(e){let t=await this.makeCAPIRequest(`/shared/${e}/messages`,"GET");return this.handleListMessages(t,!1)}async handleListMessages(e,t){if(!e.ok)if(!(404===e.status&&e.response?.headers.has("Content-Type"))||"application/json"!==e.response.headers.get("Content-Type"))return e;else{let t=await e.response.json();return{...e,payload:t}}let a=await e.json();return t&&(Array.isArray(a.messages)&&(a.messages=a.messages.map(e=>(e.references=(0,d.q)(e.references),e))),this.listMessagesCache=a),{status:e.status,ok:!0,payload:a}}async createMessage(e,t,a,s,i,r,o){this.listMessagesCache=void 0;let n=await this.makeCAPIRequest(`/threads/${e}/messages`,"POST",{content:t,mediaContent:a,intent:s,references:i,currentURL:window.location.href,customInstructions:r,model:o,settings:h.Jt.settings??void 0});if(!n.ok)return n;let l=(await n.json()).message;return{status:n.status,ok:!0,payload:l}}async createMessageStreaming({threadID:e,messageID:t,content:a,mediaContent:s,intent:i,mode:r,references:o,context:n,confirmations:l,customInstructions:u,model:d,customCopilotID:p,parentMessageID:m,tools:f,clientToolResults:k,signal:y,skillOptions:w}){this.listMessagesCache=void 0,p&&(r="custom-copilots");let T=c.W.domPageContext&&"immersive"!==r&&"custom-copilots"!==r?function(){let e=(document.querySelector("main")||document.body).cloneNode(!0);for(let t of["script","style","svg","iframe","textarea",".js-header-wrapper",".footer",".sr-only",".react-code-file-contents"])for(let a of e.querySelectorAll(t))a.remove();for(let t of e.querySelectorAll("*")){if(!t.textContent?.trim()){t.remove();continue}let e=window.getComputedStyle(t);("none"===e.display||"hidden"===e.visibility)&&t.remove()}let t=e.querySelectorAll("p, h1, h2, h3, h4, li, td, th, blockquote, pre, code:not(pre code)"),a=[];for(let e of t){let t=g(e);t&&a.push(t)}let s=a.join(` `);return(s.length<=16e3?s:`${s.substring(0,16e3)} Content was truncated. Use the API to get full content.`).replace(/\s{2,}/g," ").trim()}():void 0,v={responseMessageID:t,content:a,intent:i,references:o,context:n,currentURL:window.location.href,streaming:!0,confirmations:l,customInstructions:u,model:d,mode:r,settings:h.Jt.settings??void 0,customCopilotID:p?.id,customCopilotOwner:p?.owner,parentMessageID:m,tools:f,clientToolResults:k,mediaContent:s,skillOptions:w,pageContext:T,requestTrace:h.Jt.getTracingRequestedFlag()},_=this.processQueryParams(new URLSearchParams(window.location.search)),C=await this.makeCAPIRequest(`/threads/${e}/messages?${_.toString()}`,"POST",v,!0,void 0,y);return C.ok?{status:C.status,ok:!0,response:C}:C}processQueryParams(e){let t=["instruction_prompt"],a=new URLSearchParams;for(let[s,i]of e)t.includes(s)&&a.append(s,i);return a}async listModels(){let e=await this.makeCAPIRequest("/models","GET",void 0,!1,"");if(!e.ok)return e;let t=await e.json();return{status:e.status,ok:!0,payload:t.data}}async setModelPolicyState(e,t){let a=await this.makeCAPIRequest(`/models/${e}/policy`,"POST",{state:t},!1,"");if(!a.ok)return Promise.reject(Error(`Failed to update model policy state: ${a.status}`))}async getSimpleCompletion(e,t){let a=(0,m.wv)(),s=t??a.id,i=await this.makeCAPIRequest("/chat/completions","POST",{messages:[{role:"user",content:e}],selectedModel:s,stream:!1},!1,"");if(!i.ok)return i;let r=(await i.json()).choices[0]?.message?.content||"";return{status:i.status,ok:!0,payload:r}}async sendFeedback({feedback:e,feedbackChoice:t,messageId:a,threadId:s,textResponse:i}){let r=await this.makeDotcomRequest(`${this.urlPathPrefix}/feedback`,"POST",{feedback:e,feedback_choice:t,message_id:a,thread_id:s,text_response:i});return r.ok?{status:r.status,ok:!0,payload:null}:r}async listDocsets(){let e=await this.fetchDocsetsResponse();return e.ok?{status:200,ok:!0,payload:e.payload.knowledgeBases}:e}async listAdministratedCopilotEnterpriseOrganizations(){let e=await this.fetchDocsetsResponse();return e.ok?{status:200,ok:!0,payload:e.payload.administratedCopilotEnterpriseOrganizations}:e}fetchDocsetsResponse(){return this.docsetsPromise||(this.docsetsPromise=this.docsetRequestPromise()),this.docsetsPromise}async docsetRequestPromise(){let e=await this.makeDotcomRequest("/github-copilot/docs/docsets","GET");return e.ok?{status:200,ok:!0,payload:await e.json()}:e}async deleteDocset(e){let t=await this.makeDotcomRequest(`/copilot/docsets/${e.id}`,"DELETE");return t.ok?{status:t.status,ok:!0,payload:null}:t}async listRepoFiles(e,t=!1){let a=(0,o.ClY)({repo:e,commitOid:e.commitOID,includeDirectories:t});return this.repoFilesCache.get(a)}async querySymbols(e,t){return await this.blackbirdCaches.setupWarmCachesLoop(),this.querySymbolsCache.get(e.ownerLogin,e.name,t)}async fetchImplicitContext(e,t,a){let s=await this.makeDotcomRequest(`${this.urlPathPrefix}/implicit-context/${t}/${a}/${encodeURIComponent(e)}`,"GET");return s.ok?{status:s.status,ok:s.ok,payload:await s.json()}:s}async fetchRepo(e){let t;if(this.repoDetailsCache.has(e))t=this.repoDetailsCache.get(e);else{let a=await this.makeDotcomRequest(`${this.urlPathPrefix}/repositories/${e}`,"GET");if(!a.ok)return a;t=await a.json(),this.repoDetailsCache.set(e,t)}return{status:200,ok:!0,payload:t}}async fetchFileContents(e,t,a){let s=await this.makeDotcomRequest(`${this.urlPathPrefix}/file_contents/${e}/${t}/${a}`,"GET");return s.ok?{status:200,ok:!0,payload:await s.json()}:s}async listAgents(e){let t=await (0,n.lS)(e);if(!t.ok)return{status:t.status,ok:!1,error:u.nN[t.status]||u.DW};let a=await t.json();return{status:t.status,ok:t.ok,payload:a}}async listCustomCopilots(){let e=await (0,n.lS)(`${this.urlPathPrefix}/custom_copilots`);if(!e.ok)return{status:e.status,ok:!1,error:u.nN[e.status]||u.DW};let t=await e.json();return{status:e.status,ok:!0,payload:t}}async fetchCopilotSpace(e){let t,{owner:a,id:s}=e;t=a?`${this.urlPathPrefix}/custom_copilots/${a}/${s}`:`${this.urlPathPrefix}/custom_copilots/${s}`;let i=await (0,n.lS)(t);if(!i.ok)return{status:i.status,ok:!1,error:u.nN[i.status]||u.DW};let r=await i.json();return{status:i.status,ok:!0,payload:r}}async fetchCustomAgents(e,t){let a=await this.makeCAPIRequest(`/agents/swe/custom-agents/${e}/${t}`,"GET",void 0,void 0,"");if(!a.ok)return 404===a.status?{status:a.status,ok:!0,payload:[]}:{status:a.status,ok:!1,error:u.nN[a.status]||u.DW};let s=(await a.json()).agents;return{status:a.status,ok:!0,payload:s}}async hydrateReference(e){if(!f.has(e.type))return{status:204,ok:!0,payload:e};let t=await this.makeDotcomRequest(`${this.urlPathPrefix}/reference_details`,"POST",{reference:e});return t.ok?{status:t.status,ok:t.ok,payload:await t.json()}:t}async fetchLanguageForFileReference(e){let{repoOwner:t,repoName:a}=e,s=window.btoa(e.path),i=(0,o.RT3)({ownerLogin:t,name:a},s,!0),r=await this.makeDotcomRequest(i,"GET");return r.ok?{status:r.status,ok:r.ok,payload:await r.json()}:r}async fetchAutocompleteIssues(e,t){let a=await this.makeDotcomRequest(`/copilot/chat/autocomplete/issues?repo=${e}&q=${t}`,"GET");return a.ok?await a.json():[]}async fetchAutocompletePullRequests(e,t){let a=await this.makeDotcomRequest(`/copilot/chat/autocomplete/pulls?repo=${e}&q=${t}`,"GET");return a.ok?await a.json():[]}async fetchAutocompleteDiscussions(e,t){let a=await this.makeDotcomRequest(`/copilot/chat/autocomplete/discussions?repo=${e}&q=${t}`,"GET");return a.ok?await a.json():[]}async makeDotcomRequest(e,t,a){let s={};for(let e of(0,p.f)()){let t=e.split("="),a=t[0]?.replaceAll("_","-"),i="1";t.length>1&&(i=t[1]),s[`X-Experiment-${a}`]=i}let i=await this.copilotAuthTokenProvider.getAuthToken();s["X-Copilot-Api-Token"]=i.value;try{let i=await (0,n.lS)(e,{method:t,body:a,headers:s});if(i.ok)return i;return{status:i.status,ok:!1,error:u.nN[i.status]||u.DW}}catch{return{status:500,ok:!1,error:u.DW}}}get directConnectConfiguration(){return{integrationID:"copilot-chat"}}async makeCAPIRequest(e,t,a,s=!1,i="/github/chat",r){let o=this.apiURL,n=await this.copilotAuthTokenProvider.getAuthToken();return await (0,u.p)({basePath:o+i,path:e,method:t,body:a,streamingResponse:s,authToken:n,integrationId:this.directConnectConfiguration.integrationID,realIp:this.realIp,signal:r,apiVersion:this.apiVersion})}async fetchTracesByThreadID(e,t){let a=`/thread/${e}`;t&&(a+=`?sharedID=${encodeURIComponent(t)}`);let s=await this.makeCAPIRequest(a,"GET",void 0,!1,"/traces");if(!s.ok)return s;let i=await this.processTracesResponse(s);return{status:s.status,ok:!0,payload:i}}async fetchCoffeTrace(e){let t=await this.makeCAPIRequest(`/evaluation/thread/${e}`,"GET",void 0,!1,"/traces");if(!t.ok)return t;let a=await this.processTracesResponse(t);return{status:t.status,ok:!0,payload:a}}async processTracesResponse(e){let t=await e.json(),a=[];for(let e of t)e.spans&&Array.isArray(e.spans)&&e.id&&a.push({id:e.id,spans:e.spans});return a}async deleteTrace(e,t){let a=await this.makeCAPIRequest(`/thread/${e}/trace/${t}`,"DELETE",void 0,!1,"/traces");return a.ok?{status:a.status,ok:!0,payload:null}:a}async deleteTracesForThread(e){let t=await this.makeCAPIRequest(`/thread/${e}`,"DELETE",void 0,!1,"/traces");return t.ok?{status:t.status,ok:!0,payload:null}:t}constructor(e,t,a,o){(0,s._)(this,"apiURL",void 0),(0,s._)(this,"urlPathPrefix","/github-copilot/chat"),(0,s._)(this,"docsetsPromise",void 0),(0,s._)(this,"repoDetailsCache",new Map),(0,s._)(this,"listMessagesCache",void 0),(0,s._)(this,"copilotAuthTokenProvider",void 0),(0,s._)(this,"blackbirdCaches",new i.L),(0,s._)(this,"realIp",void 0),(0,s._)(this,"apiVersion",void 0),(0,s._)(this,"listRepoFilesImpl",async e=>{let t=await this.makeDotcomRequest(e,"GET");return t.ok?{status:200,ok:!0,payload:await t.json()}:t}),(0,s._)(this,"repoFilesCache",new l.d(this.listRepoFilesImpl)),(0,s._)(this,"querySymbolsImpl",async(e,t,a)=>{let s=await this.makeDotcomRequest(`/search/suggestions?query=repo:${e}/${t} ${a}`,"GET");return s.ok?{status:200,ok:!0,payload:(await s.json()).suggestions.filter(e=>"SUGGESTION_KIND_SYMBOL"===e.kind)}:s}),(0,s._)(this,"querySymbolsCache",new l.d(this.querySymbolsImpl)),this.apiURL=e,this.copilotAuthTokenProvider=new r.J(t.map(e=>e.id)),this.realIp=a||"",this.apiVersion=o}};let g=e=>{let t=e.tagName.toLowerCase(),a=e.textContent;if(!a||!a.trim())return null;let s=a.trim();switch(t){case"h1":return`# ${s}`;case"h2":return`## ${s}`;case"h3":return`### ${s}`;case"h4":return`#### ${s}`;case"p":default:return s;case"li":return`\u{2022} ${s}`;case"code":return`\`${s}\``;case"pre":return`\`\`\` ${s} \`\`\``;case"blockquote":return`> ${s}`}}},33535:(e,t,a)=>{a.d(t,{AI:()=>r,HN:()=>c,R:()=>n,Rs:()=>u,Sk:()=>d,XG:()=>o,tQ:()=>h});var s=a(96540),i=a(49835);function r(e){let[t]=(0,s.useState)(()=>new i.Lj(e));return t}function o(e){let t=(0,s.useRef)(null);null===t.current&&(t.current=new i.Lj(e));let a=(0,s.useCallback)(e=>{null!==t.current&&(t.current.value=e)},[]);return[t,a]}function n(...e){let[t]=(0,s.useState)(()=>new i.Es(...e));return t}let l=Symbol("no value");function u(e,t){let a=(0,s.useRef)(e.value),i=(0,s.useRef)(t);(0,s.useEffect)(()=>{i.current=t}),(0,s.useEffect)(()=>(a.current!==l&&a.current!==e.value&&(i.current(e.value),a.current=l),e.subscribe(e=>i.current(e))),[e])}function c(e){let[t,a]=(0,s.useState)(e.value);return u(e,e=>a(e)),t}function h(e){let[t,a]=(0,s.useState)(e.value),[i,r]=(0,s.useState)({});return u(e,e=>{a(e),r({})}),t}function d(e,t){let a=r(t(e.value));return u(e,e=>{a.value=t(e)}),a}},37294:(e,t,a)=>{a.d(t,{hh:()=>f,jR:()=>k,Kf:()=>g});var s=a(74848),i=a(21728),r=a(33535),o=a(88431),n=a(96540),l=a(60803),u=a(60460);let c=new Map,h=new Set;function d(e,t){switch(t.type){case"SET_TRACE_INFO":{let{visible:a,spanNode:s,messageId:i,threadId:r,actualTraceId:o,traces:n}=t.traceInfo,l=e.traceInfo?.traces||c,u=e.traceInfo?.loadedThreadIds||h;if(n&&n.size>0){let e=new Map(l);for(let[t,a]of n)e.set(t,a);l=e}else if(s&&i&&r){let e=new Map(l),t=new Date(s.startTime).toISOString();e.set(i,{spanNode:s,threadId:r,actualTraceId:o||"",timestamp:t}),l=e}if(r&&!u.has(r)){let e=new Set(u);e.add(r),u=e}let d=void 0!==a?a:e.traceInfo?.visible||!1;return{...e,traceInfo:{visible:d,traces:l,loadedThreadIds:u}}}case"REMOVE_TRACE":{let a=new Map(e.traceInfo?.traces||[]);for(let[e,s]of a)if(s.actualTraceId===t.traceID){a.delete(e);break}return{...e,traceInfo:{visible:e.traceInfo?.visible||!1,traces:a,loadedThreadIds:e.traceInfo?.loadedThreadIds||new Set}}}case"REMOVE_TRACES_FOR_THREAD":{let a=new Map(e.traceInfo?.traces||[]);for(let[e,s]of a)s.threadId===t.threadID&&a.delete(e);return{...e,traceInfo:{visible:e.traceInfo?.visible||!1,traces:a,loadedThreadIds:e.traceInfo?.loadedThreadIds||new Set}}}}}let p=(0,n.createContext)(null),m=(0,n.createContext)(null);function f(e){let t,a,c,h,f,g,k=(0,i.c)(20),{apiURL:y,children:w,ssoOrgs:T,testReducerState:v}=e;k[0]!==v?(t=v||{},k[0]=v,k[1]=t):t=k[1];let _=t,[C,b]=(0,n.useReducer)(d,_),[P,I]=(0,r.XG)(C);return k[2]!==I||k[3]!==C||k[4]!==P.current.value?(a=()=>{C!==P.current.value&&I(C)},k[2]=I,k[3]=C,k[4]=P.current.value,k[5]=a):a=k[5],k[6]!==I||k[7]!==C||k[8]!==P?(c=[C,P,I],k[6]=I,k[7]=C,k[8]=P,k[9]=c):c=k[9],(0,o.N)(a,c),k[10]!==y||k[11]!==w||k[12]!==T?(h=(0,s.jsx)(u.Q,{apiURL:y,dispatch:b,ssoOrgs:T,children:w}),k[10]=y,k[11]=w,k[12]=T,k[13]=h):h=k[13],k[14]!==P||k[15]!==h?(f=(0,s.jsx)(m.Provider,{value:b,children:(0,s.jsx)(l.n,{value:P,children:h})}),k[14]=P,k[15]=h,k[16]=f):f=k[16],k[17]!==C||k[18]!==f?(g=(0,s.jsx)(p.Provider,{value:C,children:f}),k[17]=C,k[18]=f,k[19]=g):g=k[19],g}function g(){let e=(0,n.useContext)(p);if(!e)throw Error("useTraceState must be used within a TraceContext");return e}function k(){return(0,n.useContext)(m)}try{p.displayName||(p.displayName="TraceStateContext")}catch{}try{m.displayName||(m.displayName="TraceDispatchContext")}catch{}try{f.displayName||(f.displayName="TraceProvider")}catch{}},46062:(e,t,a)=>{a.d(t,{GF:()=>c,QA:()=>l,ZL:()=>m,eW:()=>d,fZ:()=>h,wv:()=>u});var s=a(79184),i=a(51213),r=a(35247);let o="/images/modules/marketplace/models/families/openai.svg",n=new Map([["Azure OpenAI",o],["Anthropic","/images/modules/marketplace/models/families/anthropic.svg"],["Google","/images/modules/marketplace/models/families/gemini.svg"],["xAI","/images/modules/marketplace/models/families/xai.svg"]]),l="copilot-base";function u(){return{capabilities:{family:"gpt-4.1",limits:{max_prompt_tokens:128e3,vision:{supported_media_types:["image/jpeg","image/png","image/webp","image/gif"]}},supports:{parallel_tool_calls:!0,tool_calls:!0},tokenizer:"o200k_base",type:"chat"},id:"gpt-4.1",name:"GPT-4.1",displayName:"GPT-4.1",model_picker_enabled:!0,preview:!1,vendor:"OpenAI",logoURL:o,isThirdParty:!1,hasLimitedCapabilities:!1,version:"gpt-4.1-2025-04-14"}}function c(e){let{plan:t,premiumInteractionsQuotaExceeded:a,overagesEnabled:i}=(0,s.xR)();return h(e,t,a,i)}function h(e,t,a,s){return r.W.forceLegacyChatDefaultModel?{capabilities:{family:"gpt-4o",limits:{max_prompt_tokens:2e4,vision:{supported_media_types:["image/jpeg","image/png","image/webp","image/gif"]}},supports:{parallel_tool_calls:!0,tool_calls:!0},tokenizer:"o200k_base",type:"chat"},id:"gpt-4o",name:"GPT 4o",version:"gpt-4o-2024-05-13",displayName:"GPT 4o",vendor:"Azure OpenAI",logoURL:o,hasLimitedCapabilities:!1,preview:!1,isThirdParty:!1,model_picker_enabled:!0}:function(e,t,a,s){let o=r.W.premiumRequestQuotasEnabled&&t!==i.UH.IndividualFree&&a&&!s?e?.find(e=>!0===e.is_chat_fallback):e?.find(e=>!0===e.is_chat_default);return o||u()}(e,t,!!a,!!s)}function d(e){return(e??[u()]).map(p).filter(e=>!!e).filter(e=>e.model_picker_enabled)}function p(e){var t,a,s;if("chat"!==e.capabilities.type||!((t=e).model_picker_enabled&&(!t.policy||"enabled"===t.policy.state||t.policy.terms)))return null;let i=n.get(e.vendor);return"xAI"===e.vendor&&null!==document.querySelector('[data-color-mode="dark"]')&&(i="/images/modules/marketplace/models/families/xai-dark.svg"),{...e,displayName:function(e){for(let t of f)if(e.name.endsWith(t))return e.name.replace(t,"").trim();return e.name}(e),hasLimitedCapabilities:(a=e,s=r.W.copilotChatO1Tools,"o1-ga"===a.capabilities.family?!s:"o3"===a.capabilities.family||!a.capabilities.supports.tool_calls),isThirdParty:"Azure OpenAI"!==e.vendor,logoURL:i}}function m(e){return null!=e.custom_model}let f=["(Beta)","(Preview)"]},49835:(e,t,a)=>{a.d(t,{Es:()=>ObservableMap,Lj:()=>ObservableValue,yy:()=>ObservableSet});var s=a(35750),i=a(18150),r=a(85242),o=new WeakMap;let n=class ObservableBase{subscribe(e){return(0,s._)(this,o).add(e),()=>{(0,s._)(this,o).delete(e)}}notify(e){for(let t of(0,s._)(this,o))t(e)}constructor(){(0,i._)(this,o,{writable:!0,value:new Set})}};var l=new WeakMap;let ObservableValue=class ObservableValue extends n{get value(){return(0,s._)(this,l)}set value(e){var t,a;t=(0,s._)(this,l),("object"==typeof(a=e)&&a&&"object"==typeof t&&t?function(e,t){for(let a of new Set(Object.keys(e).concat(Object.keys(t))))if(!Object.is(e[a],t[a]))return!0;return!1}(t,a):!Object.is(t,a))&&((0,r._)(this,l,e),this.notify(e))}setValue(e){this.value=e}constructor(e){super(),(0,i._)(this,l,{writable:!0,value:void 0}),(0,r._)(this,l,e)}};var u=new WeakMap,c=new WeakMap;let ObservableSet=class ObservableSet extends n{get value(){return(0,s._)(this,u)}has(e){if(!(0,s._)(this,c).has(e)){let t=new ObservableValue((0,s._)(this,u).has(e));(0,s._)(this,c).set(e,t)}return(0,s._)(this,c).get(e)}add(e){(0,s._)(this,u).has(e)||((0,s._)(this,u).add(e),(0,s._)(this,c).has(e)&&((0,s._)(this,c).get(e).value=!0),this.notify((0,s._)(this,u)))}delete(e){(0,s._)(this,u).has(e)&&((0,s._)(this,u).delete(e),(0,s._)(this,c).has(e)&&((0,s._)(this,c).get(e).value=!1),this.notify((0,s._)(this,u)))}clear(){if(0!==(0,s._)(this,u).size){for(let e of((0,s._)(this,u).clear(),(0,s._)(this,c).values()))e.value=!1;this.notify((0,s._)(this,u))}}constructor(...e){super(),(0,i._)(this,u,{writable:!0,value:void 0}),(0,i._)(this,c,{writable:!0,value:new Map}),(0,r._)(this,u,new Set(...e))}};var h=new WeakMap,d=new WeakMap,p=new WeakMap;let ObservableMap=class ObservableMap extends n{get value(){return(0,s._)(this,h)}has(e){if(!(0,s._)(this,d).has(e)){let t=new ObservableValue((0,s._)(this,h).has(e));(0,s._)(this,d).set(e,t)}return(0,s._)(this,d).get(e)}get(e){if(!(0,s._)(this,p).has(e)){let t=new ObservableValue((0,s._)(this,h).get(e));(0,s._)(this,p).set(e,t)}return(0,s._)(this,p).get(e)}set(e,t){(0,s._)(this,h).get(e)!==t&&((0,s._)(this,h).set(e,t),(0,s._)(this,d).has(e)&&((0,s._)(this,d).get(e).value=!0),(0,s._)(this,p).has(e)&&((0,s._)(this,p).get(e).value=t),this.notify((0,s._)(this,h)))}delete(e){(0,s._)(this,h).has(e)&&((0,s._)(this,h).delete(e),(0,s._)(this,d).has(e)&&((0,s._)(this,d).get(e).value=!1),(0,s._)(this,p).has(e)&&((0,s._)(this,p).get(e).value=void 0),this.notify((0,s._)(this,h)))}clear(){if(0!==(0,s._)(this,h).size){for(let e of((0,s._)(this,h).clear(),(0,s._)(this,d).values()))e.value=!1;for(let e of(0,s._)(this,p).values())e.value=void 0;this.notify((0,s._)(this,h))}}constructor(...e){super(),(0,i._)(this,h,{writable:!0,value:void 0}),(0,i._)(this,d,{writable:!0,value:new Map}),(0,i._)(this,p,{writable:!0,value:new Map}),(0,r._)(this,h,new Map(...e))}}},57872:(e,t,a)=>{a.d(t,{q:()=>s});function s(e){return Array.isArray(e)?e.filter(e=>!("refOrigin"in e&&"custom_copilot"===e.refOrigin)&&!("type"in e&&"custom-instructions"===e.type)):e}},60460:(e,t,a)=>{a.d(t,{Q:()=>p,y:()=>m});var s=a(74848),i=a(21728),r=a(96540),o=a(60803),n=a(50467),l=a(11083),u=a(20139),c=a(35247),h=a(63828);let TraceManager=class TraceManager{async fetchAndLoadTraces(e,t){if(!c.W.requestTracing||!(0,l.X)())return;let a=this.getTraceState();if(!a.traceInfo?.loadedThreadIds?.has(e))try{let s=await this.service.fetchTracesByThreadID(e,t);s.ok&&s.payload.length>0?this.addTracesToState(a,s,e):this.dispatch({type:"SET_TRACE_INFO",traceInfo:{threadId:e}})}catch{}}addTracesToState(e,t,a){let s=new Map(e.traceInfo?.traces||[]);for(let e of t.payload)for(let[,t]of(0,h.r)(e.spans).entries()){let i=new Date(t.startTime).toISOString(),r=`${a}:${i}`;s.set(r,{spanNode:t,threadId:a,actualTraceId:e.id,timestamp:i})}this.dispatch({type:"SET_TRACE_INFO",traceInfo:{traces:s,threadId:a}})}async fetchCoffeTrace(e){if(!c.W.requestTracing||!(0,l.X)())return{ok:!1,status:403,error:"Tracing not available"};let t=this.getTraceState(),a=await this.service.fetchCoffeTrace(e);if(a.ok&&a.payload.length>0)return this.addTracesToState(t,a,e),a;throw Error(`Failed to load COFFE trace: ${a.status}`)}async deleteTraceSpansForGivenThread(e){let t=await this.service.deleteTracesForThread(e);return t.ok&&this.dispatch({type:"REMOVE_TRACES_FOR_THREAD",threadID:e}),t}async deleteTrace(e,t){let a=await this.service.deleteTrace(e,t);return a.ok&&this.dispatch({type:"REMOVE_TRACE",traceID:t}),a}constructor(e,t,a,s){(0,n._)(this,"dispatch",void 0),(0,n._)(this,"service",void 0),(0,n._)(this,"getTraceState",void 0),(0,n._)(this,"showTraceDisplay",async(e,t)=>{e&&t&&await this.fetchAndLoadTraces(t),this.dispatch({type:"SET_TRACE_INFO",traceInfo:{visible:e,threadId:t??void 0}})}),this.dispatch=e,this.service=new u.k(a,s),this.getTraceState=t}};let d=(0,r.createContext)(null);function p(e){let t,a,r=(0,i.c)(8),{apiURL:n,children:l,dispatch:u,ssoOrgs:c}=e,h=(0,o.c)();r[0]!==n||r[1]!==u||r[2]!==h||r[3]!==c?(t=new TraceManager(u,h,n,c),r[0]=n,r[1]=u,r[2]=h,r[3]=c,r[4]=t):t=r[4];let p=t;return r[5]!==l||r[6]!==p?(a=(0,s.jsx)(d.Provider,{value:p,children:l}),r[5]=l,r[6]=p,r[7]=a):a=r[7],a}function m(){let e=(0,r.useContext)(d);if(null===e)throw Error("useTraceManager must be used within a TraceManagerProvider");return e}try{d.displayName||(d.displayName="TraceManagerContext")}catch{}try{p.displayName||(p.displayName="TraceManagerProvider")}catch{}},60803:(e,t,a)=>{a.d(t,{c:()=>o,n:()=>r});var s=a(96540);let i=(0,s.createContext)(null),r=i.Provider;function o(){let e=(0,s.useContext)(i);if(!e||!e.current)throw Error("useGetTraceState can only be used inside a TraceProvider");return(0,s.useCallback)(()=>e.current.value,[e])}try{i.displayName||(i.displayName="ObservableTraceStateContext")}catch{}},63828:(e,t,a)=>{a.d(t,{r:()=>s});function s(e){let t=new Map,a=[];return e.map(e=>{let s={name:e.name,spanId:e.spanId,attributes:e.attributes,startTime:e.startTime,endTime:e.endTime,children:[],sessionId:e.sessionId,userId:e.userId,input:e.input,output:e.output,metadata:e.metadata};t.set(s.spanId,s);let i=e.parentId&&t.get(e.parentId);return i?i.children.push(s):a.push(s),s}),a}},65411:(e,t,a)=>{a.d(t,{J:()=>CopilotAuthTokenProvider});var s=a(50467),i=a(65620),r=a(82075),o=a(96379);let CopilotAuthTokenProvider=class CopilotAuthTokenProvider{async getAuthToken(){let e=this.getLocalStorageAuthToken();return e?this.validateAuthToken(e):this.fetchAuthToken()}setLocalStorageAuthToken(e){this.copilotLocalStorage.setItem(this.storageKey,JSON.stringify(e.serialize()))}getLocalStorageAuthToken(){let e=this.copilotLocalStorage.getItem(this.storageKey);return e?i.Y.deserialize(JSON.parse(e)):null}removeLocalStorageAuthToken(){this.copilotLocalStorage.removeItem(this.storageKey)}async validateAuthToken(e){return e.needsRefreshing(this.ssoOrgIDs)?this.fetchAuthToken():e}fetchAuthToken(){return this.currentAuthTokenRequest||(this.currentAuthTokenRequest=this._fetchAuthToken()),this.currentAuthTokenRequest}async _fetchAuthToken(){let e=await (0,o.lS)(this.tokenEndpoint,{method:"POST"});if(e.ok){let t=await e.json();this.currentAuthTokenRequest=null;let a=i.Y.fromResult(t,this.ssoOrgIDs);return this.setLocalStorageAuthToken(a),a}throw this.currentAuthTokenRequest=null,Error("Failed to mint new auth token")}constructor(e,t="/github-copilot/chat/token",a="COPILOT_AUTH_TOKEN"){(0,s._)(this,"tokenEndpoint",void 0),(0,s._)(this,"storageKey",void 0),(0,s._)(this,"ssoOrgIDs",void 0),(0,s._)(this,"currentAuthTokenRequest",void 0),(0,s._)(this,"copilotLocalStorage",void 0),this.ssoOrgIDs=e,this.currentAuthTokenRequest=null,this.copilotLocalStorage=(0,r.A)("localStorage",{throwQuotaErrorsOnSet:!1,ttl:864e5}),this.storageKey=a,this.tokenEndpoint=t}}},65620:(e,t,a)=>{a.d(t,{Y:()=>AuthToken});var s=a(50467);let AuthToken=class AuthToken{get authorizationHeaderValue(){return`GitHub-Bearer ${this.value}`}needsRefreshing(e){return this.isExpired||this.ssoChanged(e)}get isExpired(){let e=new Date(this.expiration);return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()))e.includes(t))&&e.every(e=>this.ssoOrgIDs.includes(e)))}static fromResult(e,t){return new AuthToken(e.token,e.expiration,e.ssoOrgIDs??t)}serialize(){return{value:this.value,expiration:this.expiration,ssoOrgIDs:this.ssoOrgIDs}}static deserialize(e){return new AuthToken(e.value,e.expiration,e.ssoOrgIDs)}constructor(e,t,a){(0,s._)(this,"value",void 0),(0,s._)(this,"expiration",void 0),(0,s._)(this,"ssoOrgIDs",void 0),this.value=e,this.expiration=t,this.ssoOrgIDs=a}}},79184:(e,t,a)=>{a.d(t,{$d:()=>h,xR:()=>d});var s=a(74848),i=a(21728),r=a(69599),o=a(96540),n=a(14095),l=a(51213),u=a(35247);let c=(0,o.createContext)(void 0);function h(e){let t,a,o,h,d,p,m,f,g,k=(0,i.c)(30),{children:y,initialLicenseType:w,initialPlan:T,initialQuotas:v}=e,[_,C]=(0,n.Z)(w,T,v),b=_.licenseType,P=_.plan??null;k[0]!==_?(t=_.chatQuotaRemaining()??1/0,k[0]=_,k[1]=t):t=k[1];let I=t;k[2]!==_?(a=_.premiumInteractionsQuotaRemaining()??1/0,k[2]=_,k[3]=a):a=k[3];let R=a;k[4]!==_.quotas?(o=_.quotas?.resetDate?new Date(_.quotas.resetDate).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"",k[4]=_.quotas,k[5]=o):o=k[5];let A=o;k[6]===Symbol.for("react.memo_cache_sentinel")?(h=(0,r.G7)("copilot_simulate_quota_exceeded"),k[6]=h):h=k[6];let S=h,E=S||b===l.mF.LicensedLimited;k[7]!==_?(d=_.canPurchaseAdditionalQuota(),k[7]=_,k[8]=d):d=k[8];let q=d;k[9]!==_?(p=_.canUpgradePlan(),k[9]=_,k[10]=p):p=k[10];let D=p,L=S||E&&I<=0,O=u.W.premiumRequestQuotasEnabled&&R<=0,$=_.quotas?.overagesEnabled??!1;k[11]!==_?(m=_.eligibleForTrial(),k[11]=_,k[12]=m):m=k[12];let x=m;k[13]!==q||k[14]!==D||k[15]!==L||k[16]!==I||k[17]!==x||k[18]!==E||k[19]!==b||k[20]!==$||k[21]!==P||k[22]!==R||k[23]!==O||k[24]!==C||k[25]!==A?(f={licenseType:b,chatQuotaRemaining:I,premiumChatQuotaRemaining:R,resetDate:A,isLicensedLimited:E,chatQuotaExceeded:L,premiumInteractionsQuotaExceeded:O,reloadQuota:C,plan:P,canPurchaseAdditionalQuota:q,canUpgradePlan:D,overagesEnabled:$,eligibleForTrial:x},k[13]=q,k[14]=D,k[15]=L,k[16]=I,k[17]=x,k[18]=E,k[19]=b,k[20]=$,k[21]=P,k[22]=R,k[23]=O,k[24]=C,k[25]=A,k[26]=f):f=k[26];let j=f;return k[27]!==y||k[28]!==j?(g=(0,s.jsx)(c.Provider,{value:j,children:y}),k[27]=y,k[28]=j,k[29]=g):g=k[29],g}let d=()=>{let e=(0,o.useContext)(c);if(!e)throw Error("useEntitlement must be used within EntitlementProvider");return e};try{c.displayName||(c.displayName="EntitlementContext")}catch{}try{h.displayName||(h.displayName="EntitlementProvider")}catch{}}}]); //# sourceMappingURL=packages_copilot-chat_components_tracing_TraceProvider_tsx-baedc3c44040.js.map